//
//  SickPushImageView.m
//  QuickCure1
//
//  Created by JianFeng on 16/11/4.
//  Copyright © 2016年 maoge. All rights reserved.
//
#define KSCREEN [UIScreen mainScreen].bounds.size
#import "SickPushImageView.h"
@interface SickPushImageView()
@property(nonatomic,weak)UIWindow *window;
@property(nonatomic,weak)UIButton *button;
@property(nonatomic,weak)UIView *coverView;
@property(nonatomic,weak)UILabel *lableTop;
@property(nonatomic,weak)UILabel *lableTime;
@property(nonatomic,weak)UITextView *textView;
//图片
@property(nonatomic,weak)UIImageView *imageViews;
@end
@implementation SickPushImageView
static id _instance;
+(instancetype)sheradImgaviews
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc]init];
    });
    return _instance;
}
-(void)setupUIWithImageView:(UIImageView *)imageViews
{
    _imageViews = imageViews;
    UIWindow *windew = [UIApplication sharedApplication].keyWindow;
    UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(30, 90, 50, 50)];
    _window = windew;
    _coverView = coverView;
    coverView.layer.cornerRadius = 25;
    coverView.layer.masksToBounds = YES;
    coverView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    [windew addSubview:coverView];
    
    imageViews.frame = CGRectMake(30,50, 70, 110);
    [windew addSubview:imageViews];
    
    //放大
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        coverView.transform = CGAffineTransformMakeScale(50, 50);
        } completion:^(BOOL finished) {
             [self setupUI];
    }];
   
 }
//创建UI
-(void)setupUI
{
    UILabel *lableTop = [[UILabel alloc] init];
    [_window addSubview:lableTop];
    lableTop.frame = CGRectMake(30, 30, 100, 18);
    lableTop.text = @"点击图片选取:";
    lableTop.font = [UIFont systemFontOfSize:12];
    //label
    UILabel *lableTime = [[UILabel alloc] init];
    [_window addSubview:lableTime];
    lableTime.frame = CGRectMake(30, 170, 80, 18);
    lableTime.text = @"病例描述:";
    lableTime.font = [UIFont systemFontOfSize:12];
    //textview
    UITextView *textView = [[UITextView alloc]init];
    [_window addSubview:textView];
    textView.frame = CGRectMake(30, 190, KSCREEN.width - 60, 250 );
    
    UIButton *button = [[UIButton alloc] init];
    _button = button;
    [_window addSubview:button];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor cyanColor]];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    [button setTitle:@"保存" forState:UIControlStateNormal];
    //
    button.frame = CGRectMake((KSCREEN.width - 60) / 2, KSCREEN.height - 80, 60, 25);
    _lableTop = lableTop;
    _lableTime = lableTime;
    _textView = textView;
    //
    [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tongzhi) name:UIKeyboardWillChangeFrameNotification object:nil];
}
//button监听
-(void)clickButton{
    if (_buttonBlock){
        _buttonBlock(self.textView.text);
    }
    [_coverView removeFromSuperview];
    [_button removeFromSuperview];
    [_lableTop removeFromSuperview];
    [_lableTime removeFromSuperview];
    [_textView removeFromSuperview];
 }
//键盘的监听
-(void)tongzhi{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ViewKeyBoards)];
    [_coverView addGestureRecognizer:tap];
}
//删除通知
-(void)ViewKeyBoards
{
    [_window endEditing:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
 
}
@end
